package day0414;

import java.util.Random;
import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] arr = new int[10];
        System.out.println("请输入 10 个整数：");
        for (int i = 0; i < 10; i++) {
            arr[i] = scanner.nextInt();
        }
        System.out.println("请输入一个 0 - 9 之间的数字作为数组索引：");
        int index = scanner.nextInt();
        if (index < 0 || index > 9) {
            Random random = new Random();
            index = random.nextInt(10);
            System.out.println("输入的索引不符合要求，已随机生成一个符合要求的索引：" + index);
        }
        if (index > 0 && index < 9) {
            int temp = arr[index - 1];
            arr[index - 1] = arr[index + 1];
            arr[index + 1] = temp;
        }
        System.out.println("操作后的数组为：");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}    